
/**
 * @Author: 陈瑞鹏
 * @Date:   2023-01-11 18:21:44
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2023-01-12 15:53:35
 */
import gameCtr from "../ctrs/gameCtr";
import BaseGameLayer from "../libs/core/BaseGameLayer";
import { drawScroll2 } from "../libs/core/utils";

const { ccclass, property } = cc._decorator;
@ccclass
export default class rankLayer extends BaseGameLayer {

  @property({ type: cc.Node, tooltip: "排名节点" })
  rankNode: cc.Node = null;

  @property({ type: cc.Prefab, tooltip: "排名预制体" })
  rankPre: cc.Prefab = null;

  @property({ type: cc.Label, tooltip: "自己的排名" })
  myRank: cc.Label = null;

  onEnable(): void {
    super.onEnable();
    this.drawUI();
  }

  drawUI() {
    let list = [];
    if (gameCtr.ins.rankKey == "1") {
      if (gameCtr.ins.rankKey2 == "1") {
        list = gameCtr.ins.pvpList;
        this.myRank.string = `我的排名:${gameCtr.ins.myPvpRank}`;
      } else {
        list = gameCtr.ins.wPvpList;
        this.myRank.string = `我的排名:${gameCtr.ins.myWPvpRank}`;
      }
    } else {
      if (gameCtr.ins.rankKey2 == "1") {
        list = gameCtr.ins.mxList;
        this.myRank.string = `我的排名:${gameCtr.ins.myMxRank}`;
      } else {
        list = gameCtr.ins.wMxList;
        this.myRank.string = `我的排名:${gameCtr.ins.myWMxRank}`;
      }
    }
    drawScroll2(this.rankNode, list, this.rankPre, "rankCom", 1, 0, 10);
  }

  onRankClick(e, key) {
    gameCtr.ins.rankKey = key;
    this.drawUI();
  }

  onRankClick2(e, key) {
    gameCtr.ins.rankKey2 = key;
    this.drawUI();
  }
}